package me.like.diandian.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import me.like.diandian.R;
import me.like.diandian.util.PopUtils;


/**
 * Created by Administrator on 2017/3/7.
 */

public class SharePopup extends PopupWindow {

    private Activity context;

    private View mMenuView;




    public PopupWindow harePopup(final Activity context) {

        this.context = context;


//        if (vShadow != null){
//            vShadow.setVisibility(View.VISIBLE);
//        }else{
//            backgroundAlpha(0.5f);//让背景变暗
//        }

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.dialog_share, null);
        View viewById = mMenuView.findViewById(R.id.v_shadow);
        final PopupWindow window = PopUtils.createPopupWindow(mMenuView);
        //设置SelectPicPopupWindow的View
//        this.setContentView(mMenuView);
        window.setBackgroundDrawable(new ColorDrawable());
        //设置SelectPicPopupWindow弹出窗体可点击
        window.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        window.setAnimationStyle(R.style.popWindowAnimation);
        //mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        viewById.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                window.dismiss();
            }
        });
        mMenuView.findViewById(R.id.ly_wechat).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onItemClick(0);
                }
            }
        });
        mMenuView.findViewById(R.id.ly_friend).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onItemClick(1);
                }
            }
        });
        return window;
    }


    public onShareItemListener listener;



    public interface onShareItemListener {
        void onItemClick(int position);
    }

    public void setShareItemListener(onShareItemListener listener) {
        this.listener = listener;
    }


}
